﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
namespace lb5
{
    class ClassFM
    {
        public decimal S_p(List<Electrical> elctorlist)
        {

            decimal total_pow = 0;
            decimal[] sum = new decimal[elctorlist.Count];
            for (int i = 0; i < elctorlist.Count; i++)
            {
                sum[i] = elctorlist[i].work;
                total_pow += sum[i];
            }
            return total_pow;
        }

       

        public decimal r (int kol, int [] a)
        {           
                       
            
            List<Electrical> elctorlist = new List<Electrical>();

            Creator[] elctor = new Creator[kol];

            for (int i = 0; i < kol; i++)
            {
                if (a[i] == 1) elctor[i] = new VacuumClCreator();
                if (a[i] == 2) elctor[i] = new VMCreator();
                if (a[i] == 3) elctor[i] = new DosCreator();
                if (a[i] == 4) elctor[i] = new CymCreator();
                if (a[i] == 5) elctor[i] = new FrCreator();                
            }


            foreach (Creator cr in elctor)
            {
                if (cr is VacuumClCreator)
                    elctorlist.Add(cr.FactoryMethod(10, "бытовая техника для уборки", "пылесосить"));

                if (cr is VMCreator)
                    elctorlist.Add(cr.FactoryMethod(20, "бытовая техника для стирки", "стирать"));

                if (cr is DosCreator)
                    elctorlist.Add(cr.FactoryMethod(10, "промышленный прибор", "измерять радиационный фон"));

                if (cr is CymCreator)
                    elctorlist.Add(cr.FactoryMethod(50, "промышленный прибор", "измерять частоту "));

                if (cr is FrCreator)
                    elctorlist.Add(cr.FactoryMethod(40, "бытовая техника для хранения продуктов", "сохранять продукты свежими"));

            }

            StreamWriter output = new StreamWriter("output.txt");
            for (int i = 0; i < kol ; i++)
            {
                output.WriteLine("Обьект класса {0};\n" +
                         "Мощность: {1};\n" +
                         "Область применения: {2};\n" +
                         "Назначение: {3};\n",
                         elctorlist[i].GetType().Name,
                         elctorlist[i].work,
                         elctorlist[i].includedintheoutlet,
                         elctorlist[i].toappoint);
                

            }
            
         //   foreach (Electrical pr in elctorlist)
         //   {
         //       Console.WriteLine("Обьект класса {0};\n" +
         //"Мощность: {1};\n" +
         //"Область применения: {2};\n" +
         //"Назначение: {3};\n",
         //pr.GetType().Name,
         //pr.work,
         //pr.includedintheoutlet,
         //pr.toappoint);
         //   }
            //Console.WriteLine("Общая мощность:");
            decimal tp;
            S_p(elctorlist);
            tp =S_p(elctorlist);
            output.Close();
            return tp; 
            //Console.ReadLine();
        }

       public abstract class Electrical
        {
            public decimal power;
            public string operatinginstructions;
            public string appointment;
            public abstract decimal work { get; set; }
            public abstract string includedintheoutlet { get; set; }
            public abstract string toappoint { get; set; }
        }
        abstract class Creator
        {
            public abstract Electrical FactoryMethod();
            public abstract Electrical FactoryMethod(decimal power);
            public abstract Electrical FactoryMethod(decimal power, string operatinginstructions);
            public abstract Electrical FactoryMethod(decimal power, string operatinginstructions, string appointment);
        }
        class household_appliances : Electrical
        {
            public override decimal work
            {
                get { return power; }
                set
                {
                    power = value;
                    //GlPower += value; 
                }

            }
            public override string includedintheoutlet
            {
                get { return operatinginstructions; }
                set { operatinginstructions = value; }
            }
            public override string toappoint
            {
                get { return appointment; }
                set { appointment = value; }
            }
            public char kind;
            public void doinghousework() { }
        }

        class Electrical_industry : Electrical
        {
            public override decimal work
            {
                get { return power; }
                set
                {
                    power = value;
                    //GlPower += value; 
                }

            }
            public override string includedintheoutlet
            {
                get { return operatinginstructions; }
                set { operatinginstructions = value; }
            }
            public override string toappoint
            {
                get { return appointment; }
                set { appointment = value; }
            }
            public char kind;
            public char areaindustry;
            public void workinindustry() { }
        }

        class network
        {
            public double power;

            public void countpower()
            {
                //decimal total_pow = 0;
                //decimal[] sum = new decimal[Electrical.Count];
                //for (int i = 0; i < Electrical.Count; i++)
                //{
                //    sum[i] = Electrical[i].work;
                //    total_pow += sum[i];
                //}
            
            }
        }

        class vacuum_cleaner : household_appliances
        {
            private decimal _power { get; set; }
            private string _operatinginstructions { get; set; }
            private string _appointment { get; set; }



            public vacuum_cleaner() : this(0) { }
            public vacuum_cleaner(decimal _power) :
                this(_power, null) { }
            public vacuum_cleaner(decimal _power, string _operatinginstructions) :
                this(_power, _operatinginstructions, null) { }
            public vacuum_cleaner(decimal _power, string _operatinginstructions, string _appointment)
            {
                this._power = _power;
                this._operatinginstructions = _operatinginstructions;
                this._appointment = _appointment;
            }

            public override decimal work
            {
                get { return _power; }
                set
                {
                    power = value;
                    //GlPower += value; 
                }

            }
            public override string includedintheoutlet
            {
                get { return _operatinginstructions; }
                set { _operatinginstructions = value; }
            }
            public override string toappoint
            {
                get { return _appointment; }
                set { _appointment = value; }
            }


            public void cleanthecarpet()
            {
            }
        }

        class washing_machine : household_appliances
        {
            private decimal _power { get; set; }
            private string _operatinginstructions { get; set; }
            private string _appointment { get; set; }

            public washing_machine() : this(0) { }
            public washing_machine(decimal _power) : this(_power, null) { }
            public washing_machine(decimal _power, string _operatinginstructions) :
                this(_power, _operatinginstructions, null) { }
            public washing_machine(decimal _power, string _operatinginstructions, string _appointment)
            {
                this._power = _power;
                this._operatinginstructions = _operatinginstructions;
                this._appointment = _appointment;
            }

            public override decimal work
            {
                get { return _power; }
                set
                {
                    power = value;
                    //GlPower += value; 
                }

            }
            public override string includedintheoutlet
            {
                get { return _operatinginstructions; }
                set { _operatinginstructions = value; }
            }
            public override string toappoint
            {
                get { return _appointment; }
                set { _appointment = value; }
            }

            public char methodofdownloading;
            public void wash()
            {
            }
        }

        class dosimeter : Electrical_industry
        {

            private decimal _power { get; set; }
            private string _operatinginstructions { get; set; }
            private string _appointment { get; set; }

            public dosimeter() :
                this(0) { }
            public dosimeter(decimal _power) :
                this(_power, null) { }
            public dosimeter(decimal _power, string _operatinginstructions) :
                this(_power, _operatinginstructions, null) { }
            public dosimeter(decimal _power, string _operatinginstructions, string _appointment)
            {

                this._power = _power;
                this._operatinginstructions = _operatinginstructions;
                this._appointment = _appointment;
            }

            public override decimal work
            {
                get { return _power; }
                set
                {
                    power = value;
                    //GlPower += value; 
                }

            }
            public override string includedintheoutlet
            {
                get { return _operatinginstructions; }
                set { _operatinginstructions = value; }
            }
            public override string toappoint
            {
                get { return _appointment; }
                set { _appointment = value; }
            }

        }

        class cymometer : Electrical_industry
        {

            private decimal _power { get; set; }
            private string _operatinginstructions { get; set; }
            private string _appointment { get; set; }

            public cymometer() :
                this(0) { }
            public cymometer(decimal _power) :
                this(_power, null) { }
            public cymometer(decimal _power, string _operatinginstructions) :
                this(_power, _operatinginstructions, null) { }
            public cymometer(decimal _power, string _operatinginstructions, string _appointment)
            {
                this._power = _power;
                this._operatinginstructions = _operatinginstructions;
                this._appointment = _appointment;
            }

            public override decimal work
            {
                get { return _power; }
                set
                {
                    power = value;
                    //GlPower += value; 
                }

            }
            public override string includedintheoutlet
            {
                get { return _operatinginstructions; }
                set { _operatinginstructions = value; }
            }
            public override string toappoint
            {
                get { return _appointment; }
                set { _appointment = value; }
            }

        }

        class fridge : household_appliances
        {

            private decimal _power { get; set; }
            private string _operatinginstructions { get; set; }
            private string _appointment { get; set; }

            public fridge() :
                this(0) { }
            public fridge(decimal _power) :
                this(_power, null) { }
            public fridge(decimal _power, string _operatinginstructions) :
                this(_power, _operatinginstructions, null) { }
            public fridge(decimal _power, string _operatinginstructions, string _appointment)
            {
                this._power = _power;
                this._operatinginstructions = _operatinginstructions;
                this._appointment = _appointment;
            }

            public override decimal work
            {
                get { return _power; }
                set
                {
                    power = value;
                    //GlPower += value; 
                }

            }
            public override string includedintheoutlet
            {
                get { return _operatinginstructions; }
                set { _operatinginstructions = value; }
            }
            public override string toappoint
            {
                get { return _appointment; }
                set { _appointment = value; }
            }


            public void keepfoodfresh()
            {
            }
        }

        class VacuumClCreator : Creator
        {
            public override Electrical FactoryMethod()
            {
                return new vacuum_cleaner();
            }

            public override Electrical FactoryMethod(decimal _power)
            {
                return new vacuum_cleaner(_power);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions)
            {
                return new vacuum_cleaner(_power, _operatinginstructions);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions, string _appointment)
            {
                return new vacuum_cleaner(_power, _operatinginstructions, _appointment);
            }
        }

        class VMCreator : Creator
        {
            public override Electrical FactoryMethod()
            {
                return new washing_machine();
            }

            public override Electrical FactoryMethod(decimal _power)
            {
                return new washing_machine(_power);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions)
            {
                return new washing_machine(_power, _operatinginstructions);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions, string _appointment)
            {
                return new washing_machine(_power, _operatinginstructions, _appointment);
            }
        }

        class DosCreator : Creator
        {
            public override Electrical FactoryMethod()
            {
                return new dosimeter();
            }

            public override Electrical FactoryMethod(decimal _power)
            {
                return new dosimeter(_power);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions)
            {
                return new dosimeter(_power, _operatinginstructions);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions, string _appointment)
            {
                return new dosimeter(_power, _operatinginstructions, _appointment);
            }
        }

        class CymCreator : Creator
        {
            public override Electrical FactoryMethod()
            {
                return new cymometer();
            }

            public override Electrical FactoryMethod(decimal _power)
            {
                return new cymometer(_power);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions)
            {
                return new cymometer(_power, _operatinginstructions);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions, string _appointment)
            {
                return new cymometer(_power, _operatinginstructions, _appointment);
            }
        }
        class FrCreator : Creator
        {
            public override Electrical FactoryMethod()
            {
                return new fridge();
            }

            public override Electrical FactoryMethod(decimal _power)
            {
                return new fridge(_power);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions)
            {
                return new fridge(_power, _operatinginstructions);
            }

            public override Electrical FactoryMethod(decimal _power,
                string _operatinginstructions, string _appointment)
            {
                return new fridge(_power, _operatinginstructions, _appointment);
            }
        }  
    }
}
